home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource1 / cenvid / runtime.bat < prev    next >
DOS Batch File  |  1993-09-26  |  2KB  |  56 lines

  1. @echo off
  2. REM *************************************************************************
  3. REM *** RunTime.bat - Execute commands at supplied time                   ***
  4. REM *************************************************************************
  5.  
  6. ECHO Command: %2 %3 %4 %5 %6 %7 %8 %9
  7. CEnvi %0.bat %1
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    if ( argc < 2  ||  2 != sscanf(argv[1],"%d:%d",RunHour,RunMinute)
  13.      || RunHour < 0  ||  23 < RunHour
  14.      || RunMinute < 0  ||  59 < RunMinute ) {
  15.       Instructions();
  16.    } else {
  17.       printf("Scheduled time: %02d:%02d:00\n",RunHour,RunMinute);
  18.       // Loop here forever until RunHour:RunMinute comes along, then exit
  19.       DisplayedSecond = -1; // force current time to print
  20.       do {
  21.          GetCurrentTime(CurrentHour,CurrentMinute,CurrentSecond);
  22.          if ( CurrentSecond != DisplayedSecond )
  23.             printf("\rCurrent Time:   %02d:%02d:%02d",
  24.                    CurrentHour,CurrentMinute,DisplayedSecond=CurrentSecond);
  25.       } while ( CurrentHour != RunHour  ||  CurrentMinute != RunMinute );
  26.       printf("\n");
  27.    }
  28. }
  29.  
  30. GetCurrentTime(hour,minute,second)
  31. {
  32.    now = localtime(time());
  33.    hour = now.tm_hour;
  34.    minute = now.tm_min;
  35.    second = now.tm_sec;
  36. }
  37.  
  38. Instructions()
  39. {
  40.    printf("\n");
  41.    printf("RunTime - Perform a command, with up to 7 parameters, at a specified time.\n");
  42.    printf("\n");
  43.    printf("SYNTAX: RunTime <hour>:<minute> [Command] [parm1] [parm2] [etc...]\n");
  44.    printf("\n");
  45.    printf("Where: hour   - hour of day (in 24-hour format) to run command; range 0 - 23\n");
  46.    printf("       minute - minute of hour to run command: range 0 - 59\n");
  47.    printf("\n");
  48.    printf("Examples: RunTime 14:30 chkdsk c: /f   - run chkdsk at 2:30 PM\n");
  49.    printf("          RunTime 0:00                 - pause computer until midnight\n");
  50.    printf("\n");
  51. }
  52.  
  53. :CENVI_EXIT
  54. ECHO %2 %3 %4 %5 %6 %7 %8 %9
  55. %2 %3 %4 %5 %6 %7 %8 %9
  56.